<template>
  <div class="index">
    <el-container>
      <el-header>
        <img src="../assets/logo.png" alt="" />
        <h3>电商后台管理系统</h3>
        <el-button type="info" @click="logout">退出</el-button></el-header
      >
      <el-container>
        <el-aside :width="isCollapse ? '64px' : '200px'">
          <div class="shrink" @click="open">
            |||
          </div>

          <el-menu
            default-active="1"
            class="el-menu-vertical-demo"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b"
            unique-opened
            router
            collapse-transition
            :collapse="isCollapse"
          >
            <el-submenu index="1">
              <template slot="title">
                <i class="el-icon-s-custom"></i>
                <span>用户管理</span>
              </template>
              <el-menu-item index="/userlist">用户列表</el-menu-item>
            </el-submenu>

            <el-submenu index="2">
              <template slot="title">
                <i class="el-icon-s-finance"></i>
                <span>权限管理</span>
              </template>
              <el-menu-item index="/rolelist">角色列表</el-menu-item>
              <el-menu-item index="/rightlist">权限列表</el-menu-item>
            </el-submenu>

            <el-submenu index="3">
              <template slot="title">
                <i class="el-icon-s-goods"></i>
                <span>商品管理</span>
              </template>
              <el-menu-item index="/goodslist">商品列表</el-menu-item>
              <el-menu-item index="/sortparameter">分类参数</el-menu-item>
              <el-menu-item index="/goodssort">商品分类</el-menu-item>
            </el-submenu>

            <el-submenu index="4">
              <template slot="title">
                <i class="el-icon-s-order"></i>
                <span>订单管理</span>
              </template>
              <el-menu-item index="/orderlist">订单列表</el-menu-item>
            </el-submenu>

            <el-submenu index="5">
              <template slot="title">
                <i class="el-icon-s-marketing"></i>
                <span>数据统计</span>
              </template>
              <el-menu-item index="/datareport">数据报表</el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <!-- 面包屑 -->
          <div class="bread">
            <el-breadcrumb separator-class="el-icon-arrow-right">
              <el-breadcrumb-item
                v-for="(i, k) in $store.state.bread"
                :key="k"
                :to="{ path: i.path }"
                >{{ i.name }}</el-breadcrumb-item
              >
            </el-breadcrumb>
          </div>

          <!-- 主体视图 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  name: "index",
  data() {
    return {
      isCollapse: false
    };
  },
  methods: {
    //退出登录
    logout() {
      this.$confirm("确认退出吗", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "success"
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "退出成功"
          });
          window.sessionStorage.clear();
          this.$router.push("/login");
        })
        .catch(() => {
          this.$message({
            type: "success",
            message: "取消退出"
          });
        });
    },

    //伸缩侧边栏
    open() {
      this.isCollapse = !this.isCollapse;
    }
  }
};
</script>

<style lang="scss" scoped>
.index {
  width: 100%;
  height: 100%;
  display: flex;
}
.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
  position: relative;
  display: flex;
  img {
    margin: 10px;
  }
  h3 {
    margin-left: 50px;
  }
  .el-button {
    position: absolute;
    right: 20px;
    top: 10px;
  }
}

.el-aside {
  background-color: #333744;
  color: #333;
  text-align: center;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  line-height: 160px;
  .bread {
    width: 500px;
    height: 40px;
    display: flex;
    align-items: center;
    background: #fff;
    margin-bottom: 20px;
    border-radius: 5px;
    padding-left: 10px;
  }
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}
.shrink {
  width: 100%;
  height: 20px;
  color: #fff;
  cursor: pointer;
  background: #333;
}
.el-menu-item {
  border-right: none;
}
</style>